#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
运行所有测试脚本
"""

import os
import sys
import importlib.util
import time

# 测试模块列表
TEST_MODULES = [
    "test_basic_endpoints",
    "test_simple_projects",
    "test_projects",
    "test_training_data",
    "test_text2sql",
    "test_correction",
    "test_history"
]


def import_module(module_name: str):
    """导入模块"""
    spec = importlib.util.spec_from_file_location(module_name, os.path.join(os.path.dirname(__file__), f"{module_name}.py"))
    module = importlib.util.module_from_spec(spec)
    spec.loader.exec_module(module)
    return module


def run_all_tests():
    """运行所有测试"""
    print("=" * 80)
    print("开始运行所有测试...")
    print("=" * 80)
    
    for module_name in TEST_MODULES:
        print("\n" + "=" * 80)
        print(f"运行 {module_name}...")
        print("=" * 80)
        
        try:
            module = import_module(module_name)
            module.run_all_tests()
        except Exception as e:
            print(f"运行 {module_name} 时出错: {str(e)}")
        
        # 暂停一下，避免请求过快
        time.sleep(1)
    
    print("\n" + "=" * 80)
    print("所有测试完成！")
    print("=" * 80)


if __name__ == "__main__":
    run_all_tests()